﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.ServiceLocation;

namespace Easy.ServiceLocator
{
    public static class EasyServiceLocator
    {
        public static IServiceLocator _ServiceLocator { get; private set; }
        private static object _lock = new object();

        public static void SetServiceLocator(IServiceLocator serviceLocator)
        {
            if (_ServiceLocator == null)
            {
                lock (_lock)
                {
                    if (_ServiceLocator == null)
                    {
                        _ServiceLocator = serviceLocator;
                    }
                }
            }
        }

        public static IEnumerable<TService> GetAllInstances<TService>()
        {
            return _ServiceLocator.GetAllInstances<TService>();
        }

        public static IEnumerable<object> GetAllInstances(Type serviceType)
        {
            return _ServiceLocator.GetAllInstances(serviceType);
        }

        public static TService GetInstance<TService>(string key)
        {
            return _ServiceLocator.GetInstance<TService>(key);
        }

        public static TService GetInstance<TService>()
        {
            return _ServiceLocator.GetInstance<TService>();
        }

        public static object GetInstance(Type serviceType, string key)
        {
            return _ServiceLocator.GetInstance(serviceType, key);
        }

        public static object GetInstance(Type serviceType)
        {
            return _ServiceLocator.GetInstance(serviceType);
        }

        public static object GetService(Type serviceType)
        {
            return _ServiceLocator.GetService(serviceType);
        }
    }
}
